# Calculate how many calories a beer contains
module Calories

  # Calculates calories from alcohol
  #
  # @note
  #     Extract must be measured in specific gravity
  #
  # @example
  #    Calories.from_alcohol 1.055, 1.01
  #
  # @param [Float] original original gravity
  # @param [Float] terminal terminal gravity
  # @return [Fixnum] calories from alcohol
  def self.from_alcohol original, terminal
    ((1881.22 * terminal) *
    ((original - terminal) / (1.775 - original))).round
  end

  # Calculates calories from extract
  #
  # @note
  #     Extract must be measured in specific gravity
  #
  # @example
  #    Calories.from_extract 1.055, 1.01
  #
  # @param [Float] original original gravity
  # @param [Float] terminal terminal gravity
  # @return [Fixnum] calories from extract
  def self.from_extract original, terminal
     (3550.0 * terminal *
    ((0.1808 * original) + (0.8192 * terminal) - 1.0004)).round
  end

  # Calculates calories per serving; i.e. 500ml
  #
  # @note
  #     Extract must be measured in specific gravity
  #
  # @example
  #    Calories.per_serving 1.055, 1.01
  #
  # @param [Float] original original gravity
  # @param [Float] terminal terminal gravity
  # @return [Fixnum] calories per serving
  def self.per_serving original, terminal
    (from_alcohol original, terminal) +
    (from_extract original, terminal)
  end

end
